﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Vsto = Microsoft.Office.Tools;
using Word = Microsoft.Office.Interop.Word;
using System.Drawing;
using System.Windows.Forms;




namespace WordAddIn1
{
    public partial class Ribbon1 : OfficeRibbon
    {
        public Ribbon1()
        {
            InitializeComponent();
        }

        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {
           
          
        }

        private void MyBlogsBtn_Click(object sender, RibbonControlEventArgs e)
        {
          /*  WriteDlg dlg = new WriteDlg();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (!string.IsNullOrEmpty(dlg.Str))
                {
                    WriteStr(dlg.Str);
                }
            }
           */
            Vsto.CustomTaskPane myBlogsPane = Globals.ThisAddIn.CustomTaskPanes.Single(ctp=>ctp.Title=="My blogs");
            myBlogsPane.Visible = MyBlogsBtn.Checked;
        }

        private void ManageBlogsBtn_Click(object sender, RibbonControlEventArgs e)
        {
            
        }

        public void WriteStr(string str)
        {
            AddPic();
            SavePic();
           // 
       // Microsoft.Office.Interop.Word.Range WordRange =  Globals.ThisAddIn.Application.Selection.Range;
      // WordRange.Text = str;

           
        
          
        }
        public void SavePic()
        {
            if (Globals.ThisAddIn.Application.ActiveDocument.Shapes.Count < 1)
            {
                return;
            }
            object index=1;
              Word.Shape cuPic= Globals.ThisAddIn.Application.ActiveDocument.Shapes.get_Item(ref index);
              object range = System.Reflection.Missing.Value;
              cuPic.Select(ref range);
              Globals.ThisAddIn.Application.Selection.Copy();

              
              Image image = Clipboard.GetImage();
              Bitmap bitmap = new Bitmap(image);
              bitmap.Save("D:\\abc.bmp");

            
        }
        public void AddPic()
        {
            object linkToFile = false;
            object saveWithDoc = true;
            object left = 10;
            object top = 10;
            object width = 200;
            object heigth = 200;
            object anchor = System.Reflection.Missing.Value;
            string fileSrc = "D:\\test.jpg";
            Globals.ThisAddIn.Application.ActiveDocument.Shapes.AddPicture(fileSrc, ref linkToFile, ref saveWithDoc, ref left, ref top, ref width, ref heigth,ref anchor);

        }
    }
}
